package com.lemon.smartsafety.rayeye.adapter;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.LinearLayout;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.rayeye.entity.Building;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bingoogolapple.badgeview.BGABadgeLinearLayout;
import cn.bingoogolapple.badgeview.BGABadgeTextView;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class BuildingListAdapter extends LemonRcvAdapter<Building> {
    private RecyclerTClickListener<Building> mListener;

    public BuildingListAdapter(List<Building> data, RecyclerTClickListener<Building> listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new InnerItem();
    }

    public class InnerItem implements AdapterItem<Building> {


        @Bind(R.id.itemText)
        BGABadgeTextView     itemText;
        @Bind(R.id.bga_content_layout)
        BGABadgeLinearLayout bgaContentLayout;
        @Bind(R.id.ripple)
        LinearLayout ripple;
        private Building mData;
        private int      mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_single_row_arrow;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });

       /*     ripple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
                @Override
                public void onComplete(RippleView rippleView) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });*/
        }

        @Override
        public void handleData(Building data, int position) {
            mData = data;
            mPosition = position;
            if (data.getCount() == 0) {
                bgaContentLayout.showTextBadge("");
                bgaContentLayout.hiddenBadge();
            }else{
                bgaContentLayout.showTextBadge(data.getCount() + "");
            }
            itemText.setText(StringUtils.nullValue(data.getBuildingName()));
        }
    }
}
